﻿using System;
using System.Web.Mvc;
using FriendlyURL.Web.UI.Models;

namespace FriendlyURL.Web.UI.Helpers
{
    public class HttpUnauthorizedWithRedirectResult : HttpUnauthorizedResult
    {
        public string ViewName { get; set; }


        public override void ExecuteResult(ControllerContext context)
        {
            if (context == null)
                throw new ArgumentNullException("context");
            context.HttpContext.Response.StatusCode = StatusCode;

            var errorViewModel = new ErrorViewModel();

            errorViewModel.FriendlyErrorMessage = "You are not authorized to view this information.";

            var viewResult = new ViewResult
            {
                ViewData = new ViewDataDictionary(errorViewModel),
                ViewName = ViewName
            };
            viewResult.ExecuteResult(context);
        }
    }
}